package com.servlet;

import com.dao.imp.AddUpdDelDaoImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/28 14:17
 **/

@WebServlet(name = "CheckCartServlet", value = "/CheckCartServlet")
public class CheckCartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int user_id = Integer.parseInt(session.getAttribute("userId").toString());
        String sql;
        if (request.getParameter("good_id") != null) {
            int good_id = Integer.parseInt(request.getParameter("good_id"));
            sql = "UPDATE shopingchart SET isChecked=1 WHERE good_id="+good_id+" AND user_id="+user_id;
        }else {
            sql = "UPDATE shopingchart SET isChecked=1 WHERE user_id="+user_id;
        }

        AddUpdDelDaoImp addUpdDelDaoImp = new AddUpdDelDaoImp();
        addUpdDelDaoImp.addUpdDelGoods(sql);
    }
}
